package zy06;

import java.util.ArrayList;
import java.util.HashMap;

public class zy7 {
	 public static void main(String[] args) {
	        int[] arr1 = {1, 2, 3,9};
	        int[] arr2 = {3, 4, 5, 2};

	        int[] result = mergeAndRemoveDuplicates(arr1, arr2);

	        System.out.print("[");
	        for (int i = 0; i < result.length; i++) {
	            if (i > 0) {
	                System.out.print(",");
	            }
	            System.out.print(result[i]);
	        }
	        System.out.println("]");
	    }

	    public static int[] mergeAndRemoveDuplicates(int[] arr1, int[] arr2) {
	        HashMap<Integer, Integer> map = new HashMap<>();
	        for (int num : arr1) {
	            map.put(num, map.getOrDefault(num, 0) + 1);
	        }
	        for (int num : arr2) {
	            map.put(num, map.getOrDefault(num, 0) + 1);
	        }

	        ArrayList<Integer> resultList = new ArrayList<>();
	        for (int num : map.keySet()) {
	            if (map.get(num) == 1) {
	                resultList.add(num);
	            }
	        }

	        int[] result = new int[resultList.size()];
	        for (int i = 0; i < resultList.size(); i++) {
	            result[i] = resultList.get(i);
	        }

	        return result;
	    }
}
